import { Component, OnInit } from '@angular/core';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from 'src/app/core/api';
import { MessageService } from 'src/app/core/service/message.service';
import { FormBuilder, Validators } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { Router } from '@angular/router';

@Component({
	templateUrl: './classify.html',

	providers: [DatePipe],
})
export class ClassifyMgmtComponent implements OnInit {
	page: any = {
		pageNo: 1,
		mode:'',
		providerType:''
	};
	dataList = [];
	isVisible = false;
	tableLoading = false;
	modalTitle;
	selectedRowData: any = {};
	validateForm;
	constructor(private apiService: ApiService, private nzMessageService: NzMessageService, private message: MessageService, private fb: FormBuilder, private router: Router, private modal: NzModalService) {}
	ngOnInit() {
		this.message.setBreadcrumb({
			breadcrumbs: [{ name: '配置管理中心' }],
		});
		this.loadList();
	}
	loadList() {
		this.tableLoading = true;
		this.apiService.post('旅游分类列表', { ...this.page }).then((res: any) => {
			this.dataList = res.data.list;
			this.page.pageNo = res.data.pageNo;
            this.page.pages = res.data.pages * 10;
			this.tableLoading = false;
		});
	}
	changeCurrentPage(e) {
        if (e) {
            this.page.pageNo = e;
            this.loadList();
        }
	}
	delete(data){
		this.modal.confirm({
			nzTitle: '系统提示',
			nzContent: '是否删除此分类？',
			nzOkText: '确认删除',
			nzOkType: 'primary',
			nzOnOk: () => {
				this.apiService.post('删除旅游分类',{id:data.id}).then(res=>{
					this.nzMessageService.success('删除成功！');
					this.loadList();
				})
			},
			nzCancelText: '取消',
		  })
	}
	updateNumber(data){
		this.selectedRowData = {...data};
		this.isVisible = true;
	}
	handleCancel(){
		this.isVisible = false;
	}
	handleOk(){
		if(this.selectedRowData.displayPriority && /^[1-9]\d*$/.test(this.selectedRowData.displayPriority)){
			this.apiService.post('编辑旅游分类',this.selectedRowData).then((res:any)=>{
				this.nzMessageService.success('位置修改成功！');
				this.loadList();
				this.isVisible = false;
			});
		}else{
			this.nzMessageService.warning('请输入正确的分类项位置');
		}
	}
}
